package org.dandelion.papercheck.config;

import org.dandelion.papercheck.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.AuditorAware;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class JpaAuditorAware implements AuditorAware<Long> {
    private final SnowflakeIdWorker idWorker;

    @Autowired
    public JpaAuditorAware(SnowflakeProperties snowflakeProperties) {
        idWorker = new SnowflakeIdWorker(snowflakeProperties.getWorkerId(),
                snowflakeProperties.getDatacenterId());
    }

    @Override
    public Optional<Long> getCurrentAuditor() {
        return Optional.of(idWorker.nextId());
    }
}
